home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
totsrc11.zip
/
TOTMISC.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-05-04
|
16KB
|
624 lines
{ Copyright 1991 TechnoJock Software, Inc. }
{ All Rights Reserved }
{ Restricted by License }
{ Build # 1.10 }
Unit totMISC;
{$I TOTFLAGS.INC}
{
Development Notes: 1.00a May 28 91 Added MiscInit to Interface
1.00b Jul 10 91 Added directory check in ValidFilename
1.00c Oct 9 91 Corrected FSize
1.00d Nov 6 91 Improved ValidFilename
1.10 Dec 15 92 DPMI Update - changed ResetPrinter
}
INTERFACE
Uses DOS, CRT, totSTR, totFAST;
var
LPTport:byte; {0=lpt1, 1=lpt2, 2=lpt3}
procedure Swap(var A,B:longint);
function WithinRange(Min,Max,Test: longint): boolean;
function Exist(Filename:string):boolean;
function CopyFile(SourceFile, TargetFile:string): shortint;
function DeleteFile(Filename:string): shortint;
function RenameFile(Oldname,NewName:string):shortint;
function FSize(Filename:string): longint;
function FileDrive(Full:string): string;
function FileDirectory(Full:string): string;
function FileName(Full:string): string;
function FileExt(Full:string): string;
function SlashedDirectory(Dir:string):string;
function PrinterStatus:byte;
function AlternatePrinterStatus:byte;
function PrinterReady :boolean;
procedure ResetPrinter;
procedure PrintScreen;
procedure Beep;
function CurrentTime: string;
function ParamLine: String;
function ParamVal(Marker:string): string;
function Frequency(Match:string;Source:string): byte;
function ValidFileName(FN:string): shortint;
procedure ResetStartUpMode;
function RunAnything(Command: string):integer;
function RunEXECOM(Progname, Params: string):integer;
function RunDOS(Msg:string):integer;
procedure MiscInit;
IMPLEMENTATION
VAR
StartTop, {used to record initial screen state when program is run}
StartBot : Byte;
StartMode : word;
procedure Swap(var A,B:longint);
{}
var Temp: longint;
begin
Temp := A;
A := B;
B := Temp;
end; {Swap}
function WithinRange(Min,Max,Test: longint): boolean;
{}
begin
if Min > Max then
Swap(Min,Max);
WithinRange := (Test >= Min) and (Test <= Max);
end; {WithinRange}
function Exist(Filename:string):boolean;
{returns true if file exists}
var Inf: SearchRec;
begin
findfirst(Filename,AnyFile,Inf);
Exist := (DOSError = 0);
end; {func Exist}
function CopyFile(SourceFile, TargetFile:string): shortint;
{return codes: 0 successful
1 source and target the same
2 cannot open source
3 unable to create target
4 error during copy
}
var
Source,
Target: file;
BRead,
Bwrite: word;
FileBuf: array[1..2048] of char;
begin
if SourceFile = TargetFile then
CopyFile := 1
else
begin
assign(Source,SourceFile);
{$I-}
reset(Source,1);
{$I+}
if IOResult <> 0 then
CopyFile := 2
else
begin
Assign(Target,TargetFile);
{$I-}
Rewrite(Target,1);
{$I+}
if IOResult <> 0 then
CopyFile := 3
else
begin
repeat
blockread(Source,FileBuf,SizeOf(FileBuf),BRead);
blockwrite(Target,FileBuf,Bread,Bwrite);
until (Bread = 0) or (Bread <> BWrite);
close(Source);
close(Target);
if Bread <> Bwrite then
CopyFile := 4
else
CopyFile := 0;
end;
end;
end;
end; {CopyFile}
function FSize(Filename:string): longint; {1.00c}
{returns -1 if file not found}
var FileInfo: SearchRec;
begin
Findfirst(Filename,anyfile,FileInfo);
if DOSError = 0 then
FSize := FileInfo.Size
else
FSize := -1;
end; {FSize}
function FileSplit(Part:byte;Full:string): string;
{used internally}
var
D : DirStr;
N : NameStr;
E : ExtStr;
begin
FSplit(Full,D,N,E);
Case Part of
1 : FileSplit := D;
2 : FileSplit := N;
3 : FileSplit := E;
end;
end; {FileSplit}
function FileDrive(Full:string): string;
{}
var
Temp : string;
P : byte;
begin
Temp := FileSplit(1,Full);
P := Pos(':',Temp);
if P <> 2 then
FileDrive := ''
else
FileDrive := upcase(Temp[1]);
end; {FileDrive}
function FileDirectory(Full:string): string;
{}
var
Temp : string;
P : byte;
begin
Temp := FileSplit(1,Full);
P := Pos(':',Temp);
if P = 2 then
Delete(Temp,1,2); {remove drive}
if (Temp[length(Temp)] ='\') and (temp <> '\') then
Delete(temp,length(Temp),1); {remove last backslash}
FileDirectory := Temp;
end; {FileDirectory}
function FileName(Full:string): string;
{}
begin
FileName := FileSplit(2,Full);
end; {FileName}
function FileExt(Full:string): string;
{}
var
Temp : string;
begin
Temp := FileSplit(3,Full);
if (Temp = '') or (Temp = '.') then
FileExt := temp
else
FileExt := copy(Temp,2,3);
end; {FileExt}
function SlashedDirectory(Dir:string):string;
{}
begin
if (Dir = '') or (Dir[length(Dir)] in [':','\']) then
SlashedDirectory := Dir
else
SlashedDirectory := Dir + '\';
end; {SlashedDirectory}
function PrinterStatus:byte;
{Credits: Robert W. Lewis, VA thanks! Special masking employed for non-
standard printers, e.g. daisy wheels!!! }
var Recpack : registers;
begin
with Recpack do
begin
Ah := 2;
Dx := LPTport;
intr($17,recpack);
if (Ah and $B8) = $90 then
PrinterStatus := 0 {all's well}
else if (Ah and $20) = $20 then
PrinterStatus := 1 {no Paper}
else if (Ah and $10) = $00 then
PrinterStatus := 2 {off line}
else if (Ah and $80) = $00 then
PrinterStatus := 3 {busy}
else if (Ah and $08) = $08 then
PrinterStatus := 4; {undetermined error}
end;
end; {PrinterStatus}
function AlternatePrinterStatus:byte;
var Recpack : registers;
begin
with recpack do
begin
Ah := 2;
Dx := LPTport;
intr($17,recpack);
if (Ah and $20) = $20 then
AlternatePrinterStatus := 1 {no Paper}
else if (Ah and $10) = $00 then
AlternatePrinterStatus := 2 {off line}
else if (Ah and $80) = $00 then
AlternatePrinterStatus := 3 {busy}
else if (Ah and $08) = $08 then
AlternatePrinterStatus := 4 {undetermined error}
else
AlternatePrinterStatus := 0 {all's well}
end;
end; {AlternatePrinterStatus}
function PrinterReady :boolean;
begin
PrinterReady := (PrinterStatus = 0);
end; {PrinterReady}
procedure ResetPrinter; {1.1}
var
address: ^integer;
portno,delay : integer;
begin
{$IFDEF DPMI}
address := ptr(seg0040,$0008);
{$ELSE}
address := ptr($0040,$0008);
{$ENDIF}
portno := address^ + 2;
port[portno] := 232;
for delay := 1 to 2000 do {nothing};
port[portno] := 236;
end; {ResetPrinter}
function CurrentTime: string;
var
hour,min,sec: string[2];
H,M,S,T : word;
begin
GetTime(H,M,S,T);
Str(H,Hour);
Str(M,Min);
Str(S,Sec);
if S < 10 then {pad a leading zero if sec is < 10 }
sec := '0'+sec;
if M < 10 then {pad a leading zero if min is < 10 }
min := '0'+min;
if H > 12 then { assign an a.m. or p.m. string }
begin
str(H - 12,hour);
if length(hour) = 1 then Hour := ' '+hour;
CurrentTime := hour+':'+min+':'+sec+' p.m.'
end
else if H < 1 then
CurrentTime := '12'+':'+min+':'+sec+' a.m.'
else
CurrentTime := hour+':'+min+':'+sec+' a.m.';
end; {CurrentTime}
procedure PrintScreen;
var Regpack : registers;
begin
intr($05,regpack);
end; {PrintScreen}
procedure Beep;
begin
sound(800);Delay(